package com.unbank.bhi;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class BhiXmlUtil {
	public static NodeList nl;
	private static Log log = LogFactory.getLog(BhiXmlUtil.class);
	public static Document doc;

	public static Document getDocument() {
		if (doc == null) {
			try {
				String path = BhiXmlUtil.class.getClassLoader().getResource("")
						.toURI().getPath()
						+ "bhi_config.xml";
				File file = new File(path);
				DocumentBuilderFactory factory = DocumentBuilderFactory
						.newInstance();
				DocumentBuilder builder = factory.newDocumentBuilder();
				doc = builder.parse(file);
			} catch (Exception e) {
				log.error("解析XML出错");
			}
		}
		return doc;

	}

	public static NodeList getNodeList() {
		if (doc == null) {
			getDocument();
		} else {
			if (nl == null) {
				nl = doc.getElementsByTagName("VALUE");
			}
		}
		return nl;

	}
}
